/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package map_decripter;

import entity.Cell;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import model.Arena;

/**
 *
 * @author Anh
 */
public class MapDecripter {
    public static String Convert(String s) {
        int pos = 0;
        String res = new String();
        
        while (pos < s.length()) {
            int tmp = 0;
            for (int i = pos; i < pos + 4; i++)
                if (s.charAt(i) == '1') tmp = tmp * 2 + 1;
                else tmp = tmp * 2;
            pos += 4;
            
            //System.out.println(tmp +  " " + Integer.toString(tmp));
            if (tmp < 10) res += Integer.toString(tmp);
            else res += Character.toChars(65 + tmp - 10)[0];
        }
        
        return res;
    }
    
    public static void gen(){
        // TODO code application logic here
        
        String map[];
        map = new String[Arena.getInstance().HEIGHT];
        
        for (int i = 0; i < Arena.getInstance().HEIGHT; i++) {
            map[i] = "";
            for (int j = 0; j < Arena.getInstance().WIDTH; j++)
                if (Arena.getInstance().isObstacle(new Cell(i, j))) 
                    map[i] = map[i] + "2";
                else map[i] = map[i] + "1";
                
        }
                
            
        System.out.println("Original Map:");
        for (int i = Arena.getInstance().HEIGHT - 1;i >= 0; i--)
            System.out.println(map[i]);
        System.out.println("******************");
        System.out.println();
        
        String s = new String();
        for (int i = 0; i < Arena.getInstance().HEIGHT; i++) {
            for (int j = 0; j < Arena.getInstance().WIDTH; j++)
                if (map[i].charAt(j) == '0') s += "0";
                else s += "1";
        }
        s = "11" + s + "11";
        
        System.out.println("Part 1:");
        System.out.println(Convert(s));
        System.out.println("******************");
        System.out.println();
        
        s = new String();
        for (int i = 0; i < Arena.getInstance().HEIGHT; i++) {
            for (int j = 0; j < Arena.getInstance().WIDTH; j++)
                if (map[i].charAt(j) == '2') s += "1";
                else if (map[i].charAt(j) == '1') s += "0";
        }
        while( ( ((int) s.length()) % 16) != 0) s += "0";
        
        System.out.println("Part 2:");
        System.out.println(Convert(s));
        System.out.println("******************");
        System.out.println();
            
        
    }

    
}
